import pytest
import requests


class ConfigHttp:
    def __init__(self, dic):
        self.dic = dic

    def run(self):
        # 2.1.2、进行请求，获得返回结果
        if self.dic["method"].lower() == "get":
            res = self.get()
            return res
        elif self.dic["method"].lower() == "post":
            res = self.post()
            return res

    def get(self):
        res = requests.get(url=self.dic["interfaceUrl"], params=eval(self.dic["value"]))
        return res

    def post(self):
        res = requests.post(url=self.dic["interfaceUrl"], data=eval(self.dic["value"]))
        return res


if __name__ == '__main__':
    # 准备测试数据
    data1 = {'id': '1', 'interfaceUrl': 'https://www.wanandroid.com/user/login', 'name': 'login',
             'method': 'post', 'value': "{'username':'liangchao','password':'123456'}", 'header': '{}', 'expect': '0'}
    # 实例化
    ch = ConfigHttp(data1)
    # 调用实例化
    res1 = ch.run()
    print(res1.text)
    pytest.main(["-vs"])
